package org.project.product.android.pfe.fanta.adapter;

import java.util.List;

import org.project.product.android.pfe.fanta.domain.Category;
import org.project.product.android.pfe.fanta.domain.Product;
import org.project.product.android.pfe.fanta.view.CategoryItemView;
import org.project.product.android.pfe.fanta.view.ProductItemView;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class ProductListAdapter extends BaseAdapter{

	private List<Product> products;
	
	public ProductListAdapter(List<Product> products) {
		super();
		this.products = products;
	}

	@Override
	public int getCount() {
		return products.size();
	}

	@Override
	public Object getItem(int position) {
		return products.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Product product=products.get(position);
		if(convertView!=null && convertView instanceof CategoryItemView){
			ProductItemView itemView=(ProductItemView)convertView;
			itemView.reuse(product);
			return itemView;
		}
		return new ProductItemView(parent.getContext(), product);
	}

	

}
